package top.lrshuai.websocket.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.lrshuai.websocket.user.entity.User;
import top.lrshuai.websocket.user.entity.UserGroup;
import top.lrshuai.websocket.user.service.IDoService;
import top.lrshuai.websocket.user.service.IUserGroupService;
import top.lrshuai.websocket.user.service.IUserService;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DoService implements IDoService {

    @Autowired
    private IUserService userService;

    @Autowired
    private IUserGroupService userGroupService;

    @Override
    @Transactional
    public void testTransactional() {
        List<User> list = userService.list(new LambdaQueryWrapper<User>());
        if(list.size()>0){
            list.stream().forEach(u->{
                userGroupService.save(new UserGroup().setUserId(u.getId()).setGroupId(1l).setCreateTime(LocalDateTime.now()));
            });
        }
        System.out.println("=====================");
        System.out.println("iiii="+1/0);
    }
}
